/**
 * 项目名：phms3
 * 日期：    2019-12-01 17:02:29
 * Copyright (c) 2015- HTSC-版权所有
 */
package com.joysuch.wwyt.bp.repository;

import com.joysuch.wwyt.bp.entity.BpStoreHouse;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;

import java.util.List;


/**
 * BpStoreHouseDao
 */
public interface BpStoreHouseDao extends JpaRepository<BpStoreHouse, Long>, QuerydslPredicateExecutor<BpStoreHouse> {

    public Page<BpStoreHouse> findAll(Specification<BpStoreHouse> spec, Pageable pageable);

    public BpStoreHouse save(BpStoreHouse bean);

    public void delete(BpStoreHouse bean);

    BpStoreHouse findFirstByCode(String companyCode);

    @Query(value = "select m from BpStoreHouse m where m.parentId =?1")
    List<BpStoreHouse> findByParentId(Long id);

    @Query(value = "select * from wwyt_bp_store_house where CODE LIKE CONCAT(:code,'%')", nativeQuery = true)
    List<BpStoreHouse> findHouseByCodeLike(@Param("code") String code);

    List<BpStoreHouse> findByName(String name);

    List<BpStoreHouse> findByTypeFlag(Integer typeFlag);

    List<BpStoreHouse> findByNameAndTypeFlag(String name, Integer typeFlag);

    @Query(value = "select * from wwyt_bp_store_house where  DELETE_FLAG='0' and id in (?1)", nativeQuery = true)
    List<BpStoreHouse> findByIds(List<Long> ids);
}
